package com.lorenzogao.pley.ui.fragment


import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import com.lorenzogao.pley.R
import com.lorenzogao.pley.bean.IndexBean
import com.lorenzogao.pley.ui.adapter.IndexMutilAdapter
import com.lorenzogao.pley.ui.di.component.AppComponent
import com.lorenzogao.pley.ui.di.component.DaggerRemmendComponent
import com.lorenzogao.pley.ui.di.moduel.RemmendModule
import com.lorenzogao.pley.ui.presenter.RecommendPresenter
import com.lorenzogao.pley.ui.presenter.contract.AppInfoContract
import org.jetbrains.anko.support.v4.toast
import zlc.season.rxdownload2.RxDownload
import javax.inject.Inject


/**
 * 作者：Lorenzo Gao
 * Date: 2017/12/22
 * Time: 16:31
 * 邮箱：2508719070@qq.com
 * Description:
 */
class RecommendFragment : ProgressFragment<RecommendPresenter>(), AppInfoContract.View {


    lateinit var mRecyclerView: RecyclerView


    @Inject
    lateinit var mRxDownload: RxDownload

    override fun setLayout(): Int {
        return R.layout.template_recyclerview
    }

    override fun initView() {
        initRecyclerView()
        mPresenter.requestDatas()

    }

    override fun setupActivityComponent(appComponent: AppComponent) {
        DaggerRemmendComponent.builder()
                .appComponent(appComponent)
                .remmendModule(RemmendModule(this))
                .build()
                .inject(this)
    }


    override fun showLodading() {

    }


    override fun dimissLoading() {


    }

    override fun showResult(indexBean: IndexBean) {
        mAdapter = IndexMutilAdapter(activity,mRxDownload)
        mAdapter!!.setData(indexBean)
        mRecyclerView.adapter = mAdapter
    }


    override fun showError(msg: String) {
        toast(msg)
    }


    private var mAdapter: IndexMutilAdapter? = null


    private fun initRecyclerView() {

        mRecyclerView = getContentView()!!.findViewById(R.id.rl_category)

        mRecyclerView.layoutManager = LinearLayoutManager(activity)


        mRecyclerView.itemAnimator = DefaultItemAnimator()


    }

    override fun onRequestPermissionSuccess() {
        mPresenter.requestDatas()
    }

    override fun onRequestPermissionError() {
        toast("你已拒接授权")
    }

}